define(['angularAMD', 'moment'], function (angularAMD, moment) {
    angularAMD.service('B0218Service', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog', '$calculater', '$timeout', '$mddProvider',
        function ($rootScope, $filter, $translate, config, $MMWService, $mdDialog, $calculater, $timeout, $mddProvider) {
            // 20230223 modify by Alan for#128530 : 修正select功能.
            this.init = function (plotItem, machine_no, plot_no, parent, plot_list, feedback) {
                var machine_status;
                var nowdatetime = $filter('date')(new Date(), 'yyyy/MM/dd HH:mm:ss');
                //20220302 edit by 翰鴻 for M#102396
                var mode = 'trackIn';
                var plugin = '';
                var selectPluginCount = '';
                var account = '';
                var password = '';
                var description = '';
                var plotCollectInfo = [];
                var plotSavePluginInfo = [];
                var plotSaveCollectInfo = [];
                var stampingspeed = '';
                var plotCheckInfo = [];

                var trackInInfo = {};
                var feedingOpionOn = (config.cache.sys_parameter.MaterialFeedingOption == '1');  //系統上料叫料開關
                $rootScope.dispatch_filter = {};
                $MMWService.PNIGList = {};
                var isPlugInEqualFive = false;
                var isInjectionMolding = (config.cache.sys_parameter['IsInjectionMolding'] == '1' || config.cache.sys_parameter['IsInjectionMolding'] == 'Y');
                $mddProvider.UseForm('B0218', ()=> {
                    GetisPlugInEqualFive();
                })
                //20210607 Add by Tim for#增加SQL實體分頁功能：記錄分頁資訊.
                var pageSetting = { PageNumber: 1, PageRow: 25, TotalPage: 1 };

                function GetisPlugInEqualFive() {
                    var content = {
                        op_no: plotItem.op_no
                    };
                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'check_plugIn'),
                        uri: 'ServicesSTD.Module_MAT.check_plugIn',
                        content: content,
                        success: function (data) {
                            if (parseInt(data.qty, 10) >= 1) {
                                isPlugInEqualFive = true;
                            } else {
                                isPlugInEqualFive = false;
                            }
                        }
                    });
                }

                //檢查人員上工狀態
                function laborDetailCheck(trackInInfo, callback) {
                    var plot_info_detail = trackInInfo.plot_info_detail;
                    var isLaborDetailEmpty = false;
                    for (var i = 0; i < plot_info_detail.length; i++) {
                        if (plot_info_detail[i].labor_detail.length == 0) {
                            isLaborDetailEmpty = true;
                            break;
                        }
                    }

                    if (isLaborDetailEmpty) {
                        $rootScope.showAlert($filter('translate')('B0205.showAlert.column3'));
                    } else {
                        if (callback)
                            callback();
                    }
                }

                //檢查始業點檢狀態
                function OpParameterInfo(content, callback) {
                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'start_in_op_parameter_info_get'),
                        uri: 'ServicesSTD.Module_WIP.start_in_op_parameter_info_get',
                        content: content,
                        success: function (data) {
                            var errorMsg = '', warningMsg = '';
                            //生產線時(is_line=1)且需要始業檢查(isCheckSW = 1)時始業點檢須為全通過(isCheckEQP=2)
                            if (content.is_line == '1' && data.isCheckSW == 1) {
                                if (data.start_check_result != 2) {
                                    //始業點檢尚未通過，不可進站
                                    errorMsg += $filter('translate')('B0205.msg.starting_check_fail') + '<br>';
                                }
                            }

                            //需要點檢檢查(alert_mode  = 2)
                            if (data.alert_mode == 2) {
                                errorMsg += data.alert_msg;
                            } else if (data.alert_mode == 1) {
                                warningMsg += data.alert_msg;
                            }

                            if (errorMsg != '') {
                                $rootScope.showAlert(errorMsg);
                            } else if (warningMsg != '') {
                                $rootScope.showConfirm(warningMsg, function (confirmDialog) {
                                    confirmDialog.hide();
                                    if (callback) {
                                        callback(data);
                                    }
                                });
                            } else if (callback) {
                                callback(data);
                            }
                        }
                    });
                }

                function SMES_AccLifeCheck(machine_no, plotInfoList, callback) {
                    var content = { recordlist: [] };
                    plotInfoList.forEach(function (plotInfo) {
                        content.recordlist.push({
                            op_no: plotInfo.op_no,
                            plot_no: plotInfo.plot_no,
                            machine_no: machine_no,
                            qty: plotInfo.qty,
                        });
                    });

                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'acc_life_check_process'),
                        uri: 'ServicesSTD.Module_ACC.acc_life_check_process',
                        content: content,
                        success: function (data) {
                            if (data.life_manage == '0') {
                                //警示
                                $rootScope.showConfirm(data.description, function (confirmDialog) {
                                    confirmDialog.hide();
                                    if (callback)
                                        callback();
                                });
                            } else if (data.life_manage == '1') {
                                //暫停生產
                                $rootScope.showAlert(data.description);
                            } else if (data.life_manage == '2') {
                                //核准
                                if (callback)
                                    callback();
                            }
                        }
                    });
                }

                // 輸入自動叫料數量
                function input_demand_qty(callback, feedback) {
                    $calculater.open(function (num, calcDialog) {
                        if (+num == 0) {
                            $rootScope.showAlert($filter('translate')('B0205.msg.demand_qty_must_gt_zero'));
                        } else {
                            calcDialog.hide();
                            if (callback)
                                callback((+num));
                        }
                    },
                        function (calcDialog) {
                            calcDialog.hide();
                            $rootScope.showConfirm($filter('translate')('B0205.msg.is_skip_demand'), function (confirmDialog) {
                                confirmDialog.hide();
                                if (feedback)
                                    feedback();
                            }, function (confirmDialog) {
                                confirmDialog.hide();
                                input_demand_qty(callback, feedback);
                            });
                        },
                        {
                            title: $filter('translate')('B0205.auto_demand_qty'),
                            defaultNum: 0,
                            decimal: true
                        });
                }

                // 物料存量檢查作業
                function materialStockQtyCheck_Imp(plot_check_in, callback) {
                    // 開啟系統參數才需要確認物料存量
                    if (feedingOpionOn) {
                        materialStockQtyCheck(plot_check_in, function () {
                            if (callback)
                                callback();
                        });
                    } else {
                        if (callback)
                            callback();
                    }
                }

                // 確認是否自動叫料
                function checkAutoDemandImp(plot_check_in, index, checkList, callback) {
                    if (index < plot_check_in.length) {
                        var plotItem = plot_check_in[index]; // 即將進站的批號
                        var checkItem = $filter('filter')(checkList, { plot_no: plotItem.plot_no }, true); //此批號待確認的物料
                        if (checkItem.length > 0) {
                            checkAutoDemand(plotItem, checkItem[0], function () {
                                checkAutoDemandImp(plot_check_in, ++index, checkList, callback);
                            });
                        } else {
                            checkAutoDemandImp(plot_check_in, ++index, checkList, callback);
                        }
                    } else {
                        if (callback)
                            callback();
                    }
                }

                // 顯示是否自動叫料確認視窗
                function checkAutoDemand(plotItem, checkItem, callback) {
                    if (checkItem && checkItem.auto_demand_detail && checkItem.auto_demand_detail.length > 0) {
                        var material = checkItem.auto_demand_detail.shift();

                        if (material.is_need_confirm == 'Y') {
                            $rootScope.showConfirm($filter('translate')('B0205.msg.is_need_auto_demand', {
                                plot_no: checkItem.plot_no,
                                material_no: material.material_no,
                                current_stock_qty: material.current_stock_qty,
                                min_stock_qty: material.min_stock_qty
                            }),
                                function (confirmDialog) {
                                    input_demand_qty(function (qty) {
                                        plotItem.auto_demand_detail.push(creatMaterialDetail(material, 'Y', qty));
                                        confirmDialog.hide();
                                        checkAutoDemand(plotItem, checkItem, callback);
                                    },
                                        function () {
                                            plotItem.auto_demand_detail.push(creatMaterialDetail(material, 'N', 0));
                                            confirmDialog.hide();
                                            checkAutoDemand(plotItem, checkItem, callback);
                                        });
                                },
                                function (confirmDialog) {
                                    plotItem.auto_demand_detail.push(creatMaterialDetail(material, 'N', 0));
                                    confirmDialog.hide();
                                    checkAutoDemand(plotItem, checkItem, callback);
                                });
                        } else {
                            checkAutoDemand(plotItem, checkItem, callback);
                        }
                    } else {
                        if (callback)
                            callback();
                    }
                }

                // 建立自動叫料確認結果
                function creatMaterialDetail(material, is_auto, qty) {
                    var checkResult = {
                        material_no: material.material_no,
                        substitute_material_no: material.substitute_material_no,
                        position_no: material.position_no,
                        is_auto_demand: is_auto,
                        auto_demand_qty: qty,
                        put_in_place_type: material.put_in_place_type
                    };
                    return checkResult;
                }

                //物料存量檢查
                function materialStockQtyCheck(plot_check_in, callback) {
                    var content = {
                        plot_check_in: plot_check_in
                    };
                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'material_stock_qty_check_process'),
                        uri: 'ServicesSTD.Module_WIP.material_stock_qty_check_process',
                        content: content,
                        success: function (data) {
                            if (data.check_result_detail && data.check_result_detail.length > 0) {
                                checkAutoDemandImp(plot_check_in, 0, data.check_result_detail, function () {
                                    if (callback)
                                        callback();
                                });
                            } else {
                                if (callback)
                                    callback();
                            }
                        }
                    });
                }

                function plotCheckInProcess(dialog) {
                    var report_datetime = dialog.trackInInfo.sysdate_time;// 20220330 modify by chenshibo for#108636：取AP时间
                    var content ={
                        plot_check_in:[],
                        RequestFrom: "batch"
                    };

                    trackInInfo.plot_info_detail.forEach(function (item) {
                        if (item.isSelect) {
                            item.qty = item.check_in_qty;
                            item.machine_no = machine_no;
                            item.auto_demand_detail = [];
                            item.product_no = trackInInfo.product_no;
                            item.report_datetime = report_datetime;
                            item.op_seq = '';
                            item.workstation_no = '';
                            item.plot_stamp = item.plot_stamp;
                            item.description = item.op_description;
                            item.auto_demand_detail = []; //物料明細
                            item.wait_detail = item.wait_detail;
                            item.op_plug_in_detail = [
                                {
                                    op_plug_in: dialog.op_plug_in,
                                    heat_plot_no: dialog.heat_plot_no
                                }
                            ];
                            //20220216 add by 翰鴻 for M#102822
                            item.NCFileName = item.FileName;
                            item.NCFileVersion = item.FileVersion;

                            content.plot_check_in.push(item);
                        }
                    });
                    // 20221208 modify by shiwl M#0090612 重工批扣料选择不扣料时进站物料卡控逻辑调整增加重工批减少重复扣料系统参数：0正常扣料、1辅助提醒、2不扣料  
                    dialog.material_check_for_checkin_process(content,function(){
                        SMES_AccLifeCheck(machine_no, content.plot_check_in, function () {
                            materialStockQtyCheck_Imp(content.plot_check_in, function () {
                                $MMWService.sendToServer({
                                    // uri: $mddProvider.Getfunc('B0218', 'plot_check_in_process'),
                                    uri: 'ServicesSTD.Module_WIP.plot_check_in_process',
                                    content: content,
                                    success: function (data, response) {
                                        if (data.first_check_list && data.first_check_list.length > 0) {
                                            var str = data.first_check_list.join('<br>');
                                            $rootScope.showAlert(str);
                                        }
                                        else{
                                            $rootScope.showToast(response.Message);
                                        }
                                        //进站成功后插入处理
                                        insertProductioninfData(dialog);
                                        dialog.hide();
                                        if (feedback)
                                            // 20231110 modify by wenwei for M#149719: 6009[ORACLE][在线][生产任务中心]生产线工作平台生产批批量进站后，生产线状态为闲置
                                            var work_time = $filter('date')(nowdatetime.split(' ')[0], 'yyyy/MM/dd') + " " + nowdatetime.split(' ')[1];
                                            feedback(
                                            {
                                                machine_no: machine_no,
                                                report_datetime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
                                                machine_status: '0',
                                                remark: '',
                                                handle_user_no: config.cache.account,
                                                plan_start_time: work_time,
                                                actual_end_time: work_time ,
                                                remarks: undefined
                                            }
                                            );
                                    }
                                });
                            });
                        });
                    });
                }

                //20220302 add by 翰鴻 for M#102396
                //验证插入处理(待修改)
                function insertProductioninfData(dialog) {
                    var content = {
                        plot_check_in: [],
                        detail: dialog.plotSaveCollectInfo,
                        check_detail: dialog.plotCheckInfo,
                        equipment_no: machine_no,
                        donoruser_no: dialog.account,
                        donor_remark: dialog.description,
                        insert_flg: 'fasle'
                    };


                    trackInInfo.plot_info_detail.forEach(function (item) {
                        if (item.isSelect) {
                            item.qty = item.check_in_qty;
                            item.machine_no = machine_no;
                            content.plot_check_in.push(item);
                        }
                    });

                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'insert_productioninfdata'),
                        uri: 'ServicesSTD.Module_WIP.insert_productioninfdata',
                        content: content,
                        success: function (data) {
                        }
                    });
                }

                //生產信息收集檢查
                function productionInfValidate(production_inf_detail) {
                    var msg = '';
                    production_inf_detail.forEach(function (item) {
                        if (item.productioninf_value == undefined || item.productioninf_value == '') {
                            msg += $filter('translate')('B0206.msg.productioninf_value_empty', item) + '<br>';
                        }
                    });
                    return msg;
                }

                //回到進站畫面
                function backToTrackIn(dialog) {
                    if (dialog.mode == 'lean-collect') {
                        dialog.plotCollectInfo = angular.merge([], production_inf_detail_backup);
                        production_inf_detail_backup = [];
                    }
                    dialog.mode = 'trackIn';
                }

                //20210607 Add by Tim for#增加SQL實體分頁功能：將抓資料的程式獨立出來.
                function GetPlotInfoData(param) {
                    var plotItem_workstation_no = '';
                    if (parent == 'B0201') {
                        plotItem_workstation_no = machine_no;
                    }
                    var content = {
                        machine_no: machine_no,
                        plot_no: plotItem.plot_no,
                        op_seq: '',
                        op_no: plotItem.op_no,
                        workstation_no: plotItem_workstation_no,
                        qty: plotItem.qty,
                        return_type: '3',
                        op_plug_in: plotItem.op_plug_in,
                        pageSetting: pageSetting,
                        lot_no: plot_no, // 20220810 add by zhuyuchao for#添加查询条件
                        product_no: '',
                        product_name: '',
                    };

                    // 20220810 add by zhuyuchao for#添加查询条件
                    if (param != undefined) {
                        content.lot_no = param.lot_no;
                        content.product_no = param.product_no;
                        content.product_name = param.product_name;
                        content.op_name = param.op_name;
                        content.item_spec = param.item_spec;
                        content.op_no_like = param.op_no_like;
                    }

                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'plot_info_get'),
                        uri: 'ServicesSTD.Module_WIP.plot_info_get',
                        content: content,
                        success: function (data) {
                            trackInInfo.product_no = data.plot_info_get[0].product_no;
                            // 20200713 modify by WeiTing for M#74348: 因為批次進站的生產批是在透過額外的服務取得的，所以需要再跟從工作平台帶過來的生產批進行過濾。
                            var workstation_detail = data.plot_info_get[0].workstation_detail;
                            // var filter_workstation_detail = [];
                            // filter_workstation_detail = workstation_detail.filter(workstation =>
                            //     plot_list.find(plot => plot.plot_no === workstation.plot_no && plot.op_name === workstation.op_name)
                            // )

                            trackInInfo.plot_info_detail = workstation_detail;

                            //20210607 Add by Tim：增加SQL實體分頁功能.
                            setPageSetting(trackInInfo.plot_info_detail, data.plot_info_get_totalPage);

                            // 爐批號 opPlugInDetail
                            var opPlugInDetail;
                            if (!data.op_plug_in_detail || data.op_plug_in_detail.length == 0)
                                opPlugInDetail = [];
                            else
                                opPlugInDetail = data.op_plug_in_detail[0];
                        }
                    });
                }

                //20210607 Add by Tim：增加SQL實體分頁功能.
                function setPageSetting(list, plot_info_get_totalPage) {
                    if (list) {
                        if (pageSetting) {
                            if (list.length != 0) {
                                if (plot_info_get_totalPage <= 0 || plot_info_get_totalPage == '' || plot_info_get_totalPage == undefined)
                                    pageSetting.TotalPage = 1;
                                else
                                    pageSetting.TotalPage = plot_info_get_totalPage;

                                if (pageSetting.PageNumber > pageSetting.TotalPage) {
                                    pageSetting.PageNumber = pageSetting.TotalPage;
                                }
                            } else {
                                pageSetting.TotalPage = 1;
                                pageSetting.PageNumber = 1;
                            }
                        }
                    }
                }

                

                var openDialog = function (trackInInfo, opPlugInDetail) {
                    // 20200217 modify by WeiTing for M#65968 - 共模產品自動偵測批次進站(IsInjectionMolding)。
                    var mold_no = [];
                    var group_mold_no = [];
                    for (var i = 0; i < trackInInfo.plot_info_detail.length; i++) {
                        // 帶出使用者點擊的那筆生產批的相關模具資料
                        if (trackInInfo.plot_info_detail[i].plot_no == plotItem.plot_no) {
                            mold_no = trackInInfo.plot_info_detail[i].mold_no;
                            group_mold_no = trackInInfo.plot_info_detail[i].group_mold_no;
                        }
                        // 20210526 modify by kaiinagami for M#87122 - 移除錯誤的產品編號填入
                    }
                    $mddProvider.UseForm('B0218', () =>{
                        $mdDialog.dialog(
                            'module/moduleB/program/B02/B0218/B0218.html',
                            function (dialog) {
                                dialog.plugin = plugin
                                dialog.op_plug_in = plotItem.op_plug_in
                                return {
                                    css_url: 'module/moduleB/program/B02/B0218/B0218.css',
                                    mode: mode,
                                    trackInInfo: trackInInfo,
                                    // 20200217 modify by WeiTing for M#65968 - 共模產品自動偵測批次進站(IsInjectionMolding)。 --start
                                    IsInjectionMolding: isInjectionMolding, // 共模產品模組
                                    mold_no: mold_no, // 模治具編號 
                                    group_mold_no: group_mold_no, // 組合式模治具編號
                                    op_plug_in: plotItem.op_plug_in, // 是否有爐批號 → 0(無) ; 1(有)
                                    heat_plot_no: opPlugInDetail.heat_plot_no || '', // 爐批號
                                    tmpLotNo: plot_no || '', // 20220810 add by zhuyuchao for#添加查询条件
                                    tmpProductNo: '',
                                    tmpProductName: '',
                                    page_setting: pageSetting, //20210607 Add by Tim for#增加SQL實體分頁功能：記錄分頁資訊.
                                    //20220302 add by 翰鴻 for M#102396
                                    plugin: plugin,
                                    selectPluginCount: selectPluginCount,
                                    plotCollectInfo: plotCollectInfo,
                                    plotSavePluginInfo: plotSavePluginInfo,
                                    plotSaveCollectInfo: plotSaveCollectInfo,
                                    plotCheckInfo: plotCheckInfo, //生產資訊收集验证
                                    backToTrackIn: '',//backToTrackIn,//返回进站報工畫面
                                    account: account,//授权人员
                                    password: password,//授权密码
                                    description: description,//授权备注
                                    pageInfo: () =>{   //20230926 add by shiwl	0146981: 【厦晖】批次进出站界面数据显示缺失
                                        return pageSetting.PageNumber + ' / ' + pageSetting.TotalPage
                                    },
                                    _event:{
                                        'B0218_tmpLotNO':{
                                            change:(tmpLotNO, event) =>{
                                                dialog.searchPlotList(event);
                                            }
                                        },
                                        'B0218_tmpProductNo':{
                                            change:(tmpProductNo, event) =>{
                                                dialog.searchPlotList(event);
                                            }
                                        },
                                        'B0218_tmpProductName':{
                                            change:(tmpProductName, event) =>{
                                                dialog.searchPlotList(event);
                                            },
                                            click:() =>{
                                                dialog.searchPlotList();
                                            }
                                        },
                                        // 爐批號
                                        'B0218_heat_plot_no':{
                                            isShown:(dialog.op_plug_in == '1') ? 'Y': 'N'
                                        },
                                        // 組合式模治具
                                        'B0218_group_mold_no':{
                                            isShown: isInjectionMolding ? 'Y': 'N'
                                        },
                                        // 模治具編號
                                        'B0218_mold_no':{
                                            isShown: isInjectionMolding ? 'Y': 'N'
                                        },
                                        'dialog.B0218_plot_info_detail':{
                                            selectAll: (list) => dialog.selectAll(list),
                                            select:(item, args) => dialog.itemCheck(args.index, item),
                                        },
                                        'dialog.B0218_plot_info_detail':{
                                            selectAll: (list) => dialog.selectAll(list),
                                            select:(item, args) => dialog.itemCheck(args.index, item),
                                        },
                                        // list>header 組合式治具編號
                                        'dialog.B0218_plot_info_detail.list_group_mold_no':{
                                            isShown: isInjectionMolding ? 'Y': 'N'
                                        },
                                        // list>header 治具編號
                                        'dialog.B0218_plot_info_detail.list_modl_no':{
                                            isShown: isInjectionMolding ? 'Y': 'N'
                                        },
                                        // list>header NC程式碼
                                        'dialog.B0218_plot_info_detail.NCCode':{
                                            isShown: (isPlugInEqualFive) ? 'Y': 'N'
                                        },
                                    },
                                    _fn:{
                                        //  btn 共模批選擇
                                        'B0218_match_mold':{
                                            click: () =>{
                                                dialog.selectMatchMold()
                                            },
                                            isShown: isInjectionMolding ? 'Y': 'N'
                                        },
                                        'B0218_confirm':{
                                            click: () =>{
                                                dialog.confirm()
                                            }
                                        },
                                        // btn 生产信息收集
                                        'B0218_collect':{
                                            displayText:'生产信息收集',
                                            isShown: (dialog.plugin == '3') ? 'Y' : 'N',
                                            click:()=>{
                                                dialog.collect()
                                            }
                                        },
                                        'B0218_lean_collect_Execute':{
                                            click:()=>{
                                                dialog.productionInfConfirm()
                                            }
                                        },
                                        'B0218_lean_check_cancle':{
                                            displayText:'取消',
                                            click:()=>{
                                                dialog.cancle()
                                            }
                                        },
                                        'B0218_lean_check_force':{
                                            click:()=>{
                                                dialog.force()
                                            }
                                        },
                                        'B0218_B0218_lean_collect':{
                                            isShown: 'N'
                                        },
                                        'B0218_B0218_lean_check':{
                                            isShown: 'N'
                                        },
                                        // btn 共用程式碼
                                        'B0218_CopyNCCode':{
                                            click:()=>{
                                                dialog.CopyNCCode()
                                            },
                                            isDisabled: 'Y',
                                            isShown: (isPlugInEqualFive)? 'Y': 'N'
                                        },
                                    },
                                    selectMatchMold: function () {
                                        // 如果生產批的工單沒有綁定任何模治具編號，則不做共模批選擇
                                        if (dialog.mold_no == '') {
                                            $rootScope.showAlert($filter('translate')('B0218.msg.column01'));
                                            return;
                                        }
                                        // 如果組合式模治具編號為空值(N/A)，則透過模治具編號來判斷共模批
                                        if (dialog.group_mold_no == '') {
                                            for (var i = 0; i < dialog.trackInInfo.plot_info_detail.length; i++) {
                                                var mold_no = dialog.trackInInfo.plot_info_detail[i].mold_no;
                                                // 判斷選擇的生產批的模治具編號，是否有跟所有生產批的模治具編號有共模關聯
                                                for (var a = 0; a < dialog.mold_no.length; a++) {
                                                    for (var b = 0; b < mold_no.length; b++) {
                                                        if (dialog.mold_no[a] == mold_no[b]) {
                                                            dialog.trackInInfo.plot_info_detail[i].isSelect = true;
                                                        }
                                                    }
                                                }
                                            }
                                            // 如果組合式模治具編號有值時，則透過組合式模治具來判斷共模批
                                        } else {
                                            for (var i = 0; i < dialog.trackInInfo.plot_info_detail.length; i++) {
                                                var group_mold_no = dialog.trackInInfo.plot_info_detail[i].group_mold_no;
                                                // 判斷選擇的生產批的組合式模治具編號，是否有跟所有生產批的組合式模治具編號有共模關聯
                                                for (var a = 0; a < dialog.group_mold_no.length; a++) {
                                                    for (var b = 0; b < group_mold_no.length; b++) {
                                                        if (dialog.group_mold_no[a] == group_mold_no[b]) {
                                                            dialog.trackInInfo.plot_info_detail[i].isSelect = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    // 20200217 modify by WeiTing for M#65968 - 共模產品自動偵測批次進站(IsInjectionMolding)。 --end
                                    selectAll: function (list, columnName) {
                                        if(list && list.length > 0){
                                            dialog._event['dialog.B0218_plot_info_detail'].isSelectAll = !dialog._event['dialog.B0218_plot_info_detail'].isSelectAll;
                                            list.forEach((_item, index) => {
                                                _item.isSelect = dialog._event['dialog.B0218_plot_info_detail'].isSelectAll;
                                            });
                                        }
                                        dialog.checkOneData = false;
                                        dialog._fn['B0218_CopyNCCode'].isDisabled = 'Y';
                                    },
                                    itemCheck: function (index, data) {
                                        data.isSelect = !data.isSelect;
                                        //20220214 add by 翰鴻 for M#102822
                                        var checkList = $.grep(dialog.trackInInfo.plot_info_detail, function (n, i) {
                                            return n.isSelect;
                                        });

                                        if (checkList.length == 1){ 
                                            dialog.checkOneData = true; 
                                            dialog._fn['B0218_CopyNCCode'].isDisabled = 'N';
                                        }else{
                                            dialog.checkOneData = false;
                                            dialog._fn['B0218_CopyNCCode'].isDisabled = 'Y';
                                        }
                                    },
                                    //20221118 modify by wangqq for M#0120594:批次进站前端增加卡控
                                    input_check_in_qty: function (event, data, index) {
                                        var target = event.currentTarget;
                                        // dialog.itemCheck(index, data);
                                        angular.element(target).addClass("is-focus");
                    
                                        $calculater.open(
                                        function (num, calcDialog) {
                                            if (+num > +data.QTYACIO) {
                                            $rootScope.showAlert(
                                                $filter("translate")("B0218.msg.column03") +
                                                data.QTYACIO
                                            );
                                            } else {
                                            calcDialog.hide();
                                            angular.element(target).removeClass("is-focus");
                                            if (+num != data.check_in_qty) {
                                                data.check_in_qty = num;
                                            }
                                            }
                                        },
                                        function (calcDialog) {
                                            angular.element(target).removeClass("is-focus");
                                            calcDialog.hide();
                                        },
                                        {
                                            defaultNum: data.QTYACIO,
                                            decimal: true,
                                        }
                                        );
                                    },
                                    back: function () {
                                        this.hide();
                                    },
                                    filterSearch(e){
                                            var keycode = window.event?e.keyCode:e.which; 
                                            if(keycode==13){ 
                                            dialog.searchPlotList();
                                            }
                                    },// 20221123 modify by shiwl 清空放大镜的输入筛选
                                    clearFilter(){
                                        dialog.op_no_like = '';
                                        dialog.item_spec = '';
                                        dialog.op_name = '';
                                        dialog.searchPlotList();
                                    },
                                    machine_status: machine_status,
                                    material_check_for_checkin_process:function (content, callback){
                                        $MMWService.sendToServer({
                                            // uri: $mddProvider.Getfunc('B0218', 'material_check_for_checkin_process'),
                                            uri: 'ServicesSTD.Module_WIP.material_check_for_checkin_process',
                                            content : content,
                                            success : function(data){
                                                if(data.warning_message && data.warning_message.length > 0) {
                                                    $rootScope.showConfirm(data.warning_message, function(confirmDialog){
                                                        confirmDialog.hide();
                                                        if(callback)
                                                            callback();
                                                    });
                                                } else {
                                                     if(data.need_confirm){
                                                        $rootScope.showConfirm($filter('translate')('B0205.msg.The_current_production_batch_is_a_heavy_production_batch_The_current_equipment_loading_status_is_insufficient_Is_it_still_in_the_station'), function(confirmDialog){
                                                                confirmDialog.hide();
                                                                if(callback)
                                                                    callback();
                                                            });
                                                      }else {
                                                        if(callback)
                                                          callback();
                                                      }
                                                     
                                                }
                                            }
                                        });
                                    },
                                    confirm: function () {

                                        var pluginSelect = '';
                                        var count = 0;
                                        var sucess = false;
                                        trackInInfo.plot_info_detail.forEach(function (item) {
                                            if (item.isSelect) {
                                                count = count + 1;
                                            }
                                        });

                                        if (count == 0) {
                                            $rootScope.showAlert($filter('translate')('B0218.msg.column02'));
                                        } else {
                                            $MMWService.sendToServer({
                                                // uri: $mddProvider.Getfunc('B0218', 'get_plugIn_data'),
                                                uri: 'ServicesSTD.Module_WIP.get_plugIn_data',
                                                content: { op_no: plotItem.plot_no, equipment_no: machine_no, need: 'true', plot_list: trackInInfo.plot_info_detail },
                                                success: function (data) {
                                                    data.plugin;
                                                    if (data.plugin == '3') {
                                                        if (dialog.plotSaveCollectInfo.length == 0 && dialog.plugin == '3' && dialog.plotCollectInfo.length != 0) {
                                                            $rootScope.showAlert($filter('translate')('B0206.msg.production_inf_require'), function () {
                                                                dialog.collect();
                                                            });
                                                        } else {

                                                            plotCheckInProcess(dialog);

                                                        }
                                                    } else {
                                                        plotCheckInProcess(dialog);
                                                    }


                                                }
                                            });

                                        }

                                    },
                                    //20210607 Add by Tim for#增加SQL實體分頁功能：執行前端分頁的[上一頁]功能.
                                    prevPage: function () {
                                        if (pageSetting.PageNumber - 1 <= 0) {
                                            pageSetting.PageNumber = 1;
                                        }
                                        else {
                                            pageSetting.PageNumber = pageSetting.PageNumber - 1;

                                            // 20220810 add by zhuyuchao for#添加查询条件
                                            var param = {
                                                lot_no: dialog.tmpLotNo,
                                                product_no: dialog.tmpProductNo,
                                                product_name: dialog.tmpProductName,
                                                op_no_like:dialog.op_no_like,
                                                item_spec: dialog.item_spec,
                                                op_name: dialog.op_name
                                            };

                                            GetPlotInfoData(param);
                                        }
                                    },
                                    //20210607 Add by Tim for#增加SQL實體分頁功能：執行前端分頁的[下一頁]功能.
                                    nextPage: function () {
                                        if (pageSetting.PageNumber + 1 > (pageSetting.TotalPage)) {
                                            pageSetting.PageNumber = pageSetting.TotalPage;
                                        }
                                        else {
                                            pageSetting.PageNumber = pageSetting.PageNumber + 1;

                                            // 20220810 add by zhuyuchao for#添加查询条件
                                            var param = {
                                                lot_no: dialog.tmpLotNo,
                                                product_no: dialog.tmpProductNo,
                                                product_name: dialog.tmpProductName,
                                                op_no_like:dialog.op_no_like,
                                                item_spec: dialog.item_spec,
                                                op_name: dialog.op_name
                                            };

                                            GetPlotInfoData(param);
                                        }
                                    },
                                    // 20220810 add by zhuyuchao for#添加查询条件
                                    searchPlotList: function (event) {
                                        if (!event || event.event.keyCode == 13) {
                                            var param = {
                                                lot_no: dialog.tmpLotNo,
                                                product_no: dialog.tmpProductNo,
                                                product_name: dialog.tmpProductName,
                                                op_no_like:dialog.op_no_like,
                                                item_spec: dialog.item_spec,
                                                op_name: dialog.op_name
                                            };
                                            //20221021 modify wangzy for M#0120982: 批次进站翻页报错
                                            pageSetting.PageNumber = 1;
                                            GetPlotInfoData(param);
                                        }
                                    },
                                    //20220302 add by 翰鴻 for M#102822
                                    isPlugInEqualFive: isPlugInEqualFive,
                                    CopyNCCode: function () {
                                        if (!dialog.checkOneData) return;
                                        var baseData = $.grep(dialog.trackInInfo.plot_info_detail, function (n, i) {
                                            return n.isSelect;
                                        })[0];

                                        var otherDataList = $.grep(dialog.trackInInfo.plot_info_detail, function (n, i) {
                                            return !n.isSelect;
                                        });
                                        $mddProvider.UseForm('B0218_CopyNCCode', () =>{
                                            $mdDialog.dialog(
                                                'module/moduleB/program/B02/B0218/CopyNCCode.html',
                                                function (CopyDialog) {
                                                    return {
                                                        baseData: baseData,
                                                        otherDataList: otherDataList,
                                                        _fn:{
                                                            'Execute':{
                                                                click:()=>{
                                                                    CopyDialog.confirm()
                                                                }
                                                            }
                                                        },
                                                        _event: {
                                                            'dialog.list':{
                                                                selectAll: (list) => CopyDialog.selectAll(list),
                                                                select:(item, args) => CopyDialog.itemCheck(args.index, item),
                                                            },
                                                        },
                                                        selectAll: function (list) {
                                                            if(list && list.length > 0){
                                                                CopyDialog._event['dialog.list'].isSelectAll = !CopyDialog._event['dialog.list'].isSelectAll;
                                                                list.forEach((_item, index) => {
                                                                    _item.isSelect = CopyDialog._event['dialog.list'].isSelectAll;
                                                                });
                                                            }
                                                        },
                                                        IsInjectionMolding: config.cache.sys_parameter['IsInjectionMolding'], // 共模產品模組
                                                        isPlugInEqualFive: isPlugInEqualFive,
                                                        back: function () {
                                                            trackInInfo.plot_info_detail.forEach(function (i, val) {
                                                                val.isSelect = false;
                                                            });
                                                            this.hide();
                                                        },
                                                        confirm: function () {
                                                            var checkList = $.grep(CopyDialog.otherDataList, function (n, i) {
                                                                return n.isSelect;
                                                            });
                                                            $.each(checkList, function (i, val) {
                                                                var modifyData = $.grep(trackInInfo.plot_info_detail, function (n, i) {
                                                                    return n.plot_no == val.plot_no && n.op_no == val.op_no;
                                                                })[0];
                                                                modifyData.NCCode = baseData.NCCode;
                                                                modifyData.FileName = baseData.FileName;
                                                                modifyData.FileVersion = baseData.FileVersion;
                                                            });

                                                            $.each(dialog.trackInInfo.plot_info_detail, function (i, val) {
                                                                val.isSelect = false;
                                                            });

                                                            this.hide();
                                                        },
                                                        itemCheck: function (index, data) {
                                                            data.isSelect = !data.isSelect;
                                                        },
                                                    };
                                                }
                                            );
                                        })


                                    },
                                    settingNCCode: function (dataObject) {
                                        $mddProvider.UseForm('B0218_NCCodeSetting', () =>{
                                            $mdDialog.dialog(
                                                'module/moduleB/program/B02/B0218/NCCodeSetting.html',
                                                function (NCdialog) {
                                                    return {
                                                        css_url: 'JSplugins/angular-material-lite/template/dynamicService.tmp.css',
                                                        NCType: false,
                                                        NCName: '',
                                                        NCCode: '',
                                                        hiddenFileName: '',
                                                        hiddenFileVersion: '',
                                                        _fn:{
                                                            'Execute':{
                                                                click:()=>{
                                                                    NCdialog.confirm()
                                                                }
                                                            }
                                                        },
                                                        loadNCCode: function () {
                                                            $rootScope.showQueryList({
                                                                header: [
                                                                    { label: $filter('translate')('B0205.NC_DDL.LotNo'), code: 'lotNO' },
                                                                    { label: $filter('translate')('B0205.NC_DDL.ProductNo'), code: 'ProductNO' },
                                                                    { label: $filter('translate')('B0205.NC_DDL.ProductVersion'), code: 'ProductVersion' },
                                                                    { label: $filter('translate')('B0205.NC_DDL.OPNO'), code: 'OPNo' },
                                                                    { label: $filter('translate')('B0205.NC_DDL.EquipmentNo'), code: 'EquipmentNO' },
                                                                    { label: $filter('translate')('B0205.NC_DDL.FileName'), code: 'FileName' },
                                                                    { label: $filter('translate')('B0205.NC_DDL.FileVersion'), code: 'FileVersion' }
                                                                ],
                                                                query: function (conditions, feedback) {
                                                                    //vehicle_no_info_get('', feedback);
                                                                    NCCode_info_get(feedback, dataObject.plot_no, dataObject.op_no, machine_no);
                                                                },
                                                                confirm: function (selectItem, query_dialog) {
                                                                    if (selectItem.FileName != null && selectItem.FileVersion != null) {
                                                                        NCdialog.NCCode = selectItem.FileName + '-' + selectItem.FileVersion;
                                                                        //隱藏欄位
                                                                        NCdialog.hiddenFileName = selectItem.FileName;
                                                                        NCdialog.hiddenFileVersion = selectItem.FileVersion;
                                                                    }
                                                                    query_dialog.hide();
                                                                }
                                                            });

                                                        },
                                                        back: function () {
                                                            this.hide();
                                                        },
                                                        confirm: function () {
                                                            var onlyData = $.grep(dialog.trackInInfo.plot_info_detail, function (n, i) {
                                                                return n.plot_no == dataObject.plot_no && n.op_no == dataObject.op_no;
                                                            })[0];

                                                            if (NCdialog.NCType) {
                                                                onlyData.NCCode = NCdialog.NCName;
                                                                onlyData.FileName = NCdialog.NCName == null || NCdialog.NCName == undefined ? '' : NCdialog.NCName;
                                                                onlyData.FileVersion = '-1';
                                                            }
                                                            else {
                                                                onlyData.NCCode = NCdialog.NCCode;
                                                                onlyData.FileName = NCdialog.hiddenFileName;
                                                                onlyData.FileVersion = NCdialog.hiddenFileVersion;
                                                            }
                                                            NCdialog.hide();
                                                        },
                                                        beforeShown: function () {
                                                            $MMWService.sendToServer({
                                                                // uri: $mddProvider.Getfunc('B0218', 'NCCode_info_get'),
                                                                uri: 'ServicesSTD.Module_WIP.NCCode_info_get',
                                                                content: {
                                                                    LotNO: dataObject.plot_no,
                                                                    OPNO: dataObject.op_no,
                                                                    EquipmentNO: machine_no
                                                                },
                                                                success: function (data) {
                                                                    if (data.length > 0) {
                                                                        NCdialog.NCCode = data[0].FileName + '-' + data[0].FileVersion;
                                                                        NCdialog.hiddenFileName = data[0].FileName;
                                                                        NCdialog.hiddenFileVersion = data[0].FileVersion;
                                                                    }
                                                                }
                                                            });
                                                        }
                                                    };
                                                }
                                            );
                                        })
                                    },
                                    //20220302 add by 翰鴻 for M#102396
                                    // 生产信息收集
                                    collect: function () {
                                        //dialog.mode = 'lean-collect';
                                        var count = 0;
                                        trackInInfo.plot_info_detail.forEach(function (item) {
                                            if (item.isSelect) {
                                                count = count + 1;
                                            }
                                        });

                                        if (count == 0) {
                                            $rootScope.showAlert($filter('translate')('B0218.msg.column02'));
                                        }
                                        else {
                                            if (dialog.plotCollectInfo && dialog.plotCollectInfo.length > 0) {
                                                dialog.mode = 'lean-collect';
                                                dialog.changeForm('B0218_lean_collect')
                                                dialog.production_inf_detail_backup = angular.merge([], dialog.plotCollectInfo);
                                            } else {
                                                $rootScope.showAlert($filter('translate')('B0206.showAlert.production_inf_detail_empty'));
                                            }
                                        }

                                    },
                                    switchInit: function (item) {
                                        if (!item.productioninf_value) {
                                            item.productioninf_value = '0';
                                        }
                                    },
                                    switchClick: function (item) {
                                        if (item.productioninf_value == '0') {
                                            item.productioninf_value = '1';
                                        } else {
                                            item.productioninf_value = '0';
                                        }
                                    },

                                    prevTrackIn: function () {
                                        dialog.mode = 'trackIn';
                                        // 回上一頁都不進行資料更新。
                                        dialog.waitReasonList = dialog.waitReasonListCopy;
                                        $timeout(function () {
                                            document.querySelector('.searching-func').focus();
                                        });
                                    },
                                    //回到生产资讯收集
                                    prevCheckIn: function () {
                                        dialog.mode = 'lean-collect';
                                        // 回上一頁都不進行資料更新。
                                        dialog.plotCollectInfo = angular.merge([], dialog.production_inf_detail_backup);
                                        $timeout(function () {
                                            document.querySelector('.searching-func').focus();
                                        });
                                    },
                                    //生产资讯收集确定按钮
                                    productionInfConfirm: function () {

                                        var msg = '';
                                        if (dialog.mode == 'lean-collect') {
                                            msg = productionInfValidate(dialog.plotCollectInfo);

                                        }

                                        if (msg == '') {
                                            dialog.isRequire = false;
                                            dialog.plotSaveCollectInfo = dialog.plotCollectInfo;
                                            var content = {
                                                equipment_no: machine_no,
                                                chechk_flg: 'false',
                                                plot_check_in: [],
                                                plot_check_stampingspeed: [],
                                            };
                                            dialog.plotCheckInfo = [];
                                            dialog.plotCollectInfo.forEach(function (item) {

                                                if (item.productioninf_code == 'StampingSpeed') {

                                                    content.plot_check_stampingspeed.push(item);
                                                    //进行验证
                                                    trackInInfo.plot_info_detail.forEach(function (item) {
                                                        if (item.isSelect) {
                                                            item.qty = item.check_in_qty;
                                                            item.machine_no = machine_no;
                                                            content.plot_check_in.push(item);
                                                        }
                                                    });

                                                    $MMWService.sendToServer({
                                                        // uri: $mddProvider.Getfunc('B0218', 'check_stampingspeed_info'),
                                                        uri: 'ServicesSTD.Module_WIP.check_stampingspeed_info',
                                                        content: content,
                                                        success: function (data) {
                                                            if (data.plot_check_detail.length > 0) {
                                                                dialog.mode = 'lean-check';
                                                                dialog.changeForm('B0218_lean_check')
                                                                dialog.plotCheckInfo = data.plot_check_detail;
                                                                //dialog.plotCheckInfo.push(item);

                                                            } else {
                                                                dialog.mode = 'trackIn';
                                                                dialog.changeForm()

                                                            }

                                                        }
                                                    });

                                                } else {
                                                    dialog.mode = 'trackIn';
                                                    dialog.changeForm()

                                                }
                                            });
                                        } else {
                                            dialog.isRequire = true;
                                            $rootScope.showAlert(msg);
                                        }
                                    },
                                    //取消
                                    cancle: function () {
                                        dialog.mode = 'lean-collect';
                                        dialog.changeForm('B0218_lean_collect')
                                        // 回上一頁都不進行資料更新。
                                        dialog.plotCollectInfo = angular.merge([], dialog.production_inf_detail_backup);
                                        $timeout(function () {
                                            document.querySelector('.searching-func').focus();
                                        });
                                    },
                                    //强制
                                    force: function () {
                                        $mdDialog.serviceDialog('PasswordService', {
                                            mode: 'AreaLeader',
                                            equipmentno: machine_no,
                                            feedback: function (account, password, description) {
                                                //dialog.account = account;
                                                //dialog.password = password;
                                                //dialog.description = description;
                                                dialog.mode = 'trackIn';
                                                dialog.changeForm()
                                            }
                                        });

                                        //var msg = '';
                                        ////msg = opDialogUser();
                                        //$rootScope.showAlert(opDialogUser());
                                    },
                                }
                            }
                        );
                    })
                };

                //20220302 add by 翰鴻 for M#102396
                //查询作业站属性
                $mddProvider.UseForm('B0218', ()=> {
                    (function getPlugIn() {
                        $MMWService.sendToServer({
                            // uri: $mddProvider.Getfunc('B0218', 'get_plugIn_data'),
                            uri: 'ServicesSTD.Module_WIP.get_plugIn_data',
                            content: { op_no: plotItem.plot_no, equipment_no: machine_no, need: 'true', plot_list: plot_list },
                            success: function (data) {
                                plugin = data.plugin;
                                plotCollectInfo = data.plot_detail;
                                plotSavePluginInfo = data.plot_plugin_list;

                            }
                        });
                    })();
                })

                function NCCode_info_get(callback, lotno, opno, equipmentno) {
                    $MMWService.sendToServer({
                        // uri: $mddProvider.Getfunc('B0218', 'NCCode_info_get'),
                        uri: 'ServicesSTD.Module_WIP.NCCode_info_get',
                        content: {
                            LotNO: lotno,
                            OPNO: opno,
                            EquipmentNO: equipmentno
                        },
                        success: function (data) {
                            if (callback)
                                callback(data);
                        }
                    });
                }
                $mddProvider.UseForm('B0218', ()=> {
                    (function plotInfoGet() {
                        var plotItem_workstation_no = '';
                        if (parent == 'B0201') {
                            plotItem_workstation_no = machine_no;
                        }
                        OpParameterInfo({
                            machine_no: machine_no,
                            is_line: parent == 'B0201' ? '1' : '0',
                            lot_no: plotItem.plot_no,
                            op_no: plotItem.op_no,
                            area_no: plotItem_workstation_no
                        },
                            function () {
                                var content = {
                                    machine_no: machine_no,
                                    plot_no: plotItem.plot_no,
                                    op_seq: '',
                                    op_no: plotItem.op_no,
                                    workstation_no: plotItem_workstation_no,
                                    qty: plotItem.qty,
                                    return_type: '3',
                                    op_plug_in: plotItem.op_plug_in,
                                    pageSetting: pageSetting,
                                    lot_no: plot_no//20220914 modify by maxueli M#0118808 :修改为上个页面的搜索条件

                                };
                                $MMWService.sendToServer({
                                    // uri: $mddProvider.Getfunc('B0218', 'plot_info_get'),
                                    uri: 'ServicesSTD.Module_WIP.plot_info_get',
                                    content: content,
                                    success: function (data) {
                                        trackInInfo.product_no = data.plot_info_get[0].product_no;
                                        // 20200713 modify by WeiTing for M#74348: 因為批次進站的生產批是在透過額外的服務取得的，所以需要再跟從工作平台帶過來的生產批進行過濾。
                                        var workstation_detail = data.plot_info_get[0].workstation_detail;
                                        // var filter_workstation_detail = [];
                                        // filter_workstation_detail = workstation_detail.filter(workstation =>
                                        //     plot_list.find(plot => plot.plot_no === workstation.plot_no && plot.op_name === workstation.op_name)
                                        // )

                                        trackInInfo.plot_info_detail = workstation_detail;
                                        trackInInfo.sysdate_time = data.plot_info_get[0].sysdate_time;
                                        //M#95547 for a991241234 生產批派工合併註記勾選
                                        if (plotItem.batch_mark && plotItem.batch_mark.trim() != '') {
                                            var fliter_query = {};                              //合併註記篩選條件
                                            fliter_query.batch_mark = plotItem.batch_mark;      //合併註記 tag
                                            fliter_query.op_no = plotItem.op_no;                //作業站
                                            fliter_query.status = plotItem.status;              //生產批狀態  
                                            var has_mark_lot = $filter('filter')(plot_list, fliter_query);
                                            if (has_mark_lot.length > 1) {
                                                for (var i in trackInInfo.plot_info_detail) {
                                                    var lot_query = {};
                                                    lot_query.plot_no = trackInInfo.plot_info_detail[i].plot_no;
                                                    lot_query.op_no = trackInInfo.plot_info_detail[i].op_no;
                                                    var same_mark_lot = $filter('filter')(has_mark_lot, lot_query);
                                                    if (same_mark_lot && same_mark_lot.length > 0)
                                                        trackInInfo.plot_info_detail[i].isSelect = true;
                                                }
                                            }
                                        }
                                        //20210607 Add by Tim：增加SQL實體分頁功能.
                                        setPageSetting(trackInInfo.plot_info_detail, data.plot_info_get_totalPage);

                                        // 爐批號 opPlugInDetail
                                        var opPlugInDetail;
                                        if (!data.op_plug_in_detail || data.op_plug_in_detail.length == 0)
                                            opPlugInDetail = [];
                                        else
                                            opPlugInDetail = data.op_plug_in_detail[0];

                                        laborDetailCheck(trackInInfo, function () {
                                            openDialog(trackInInfo, opPlugInDetail);
                                        });
                                    }
                                });
                            });
                    })();
                })
            };
        }]);
});
